<?php
namespace PartnerAdmin\Model;
use Think\Model;
class GoodsModel extends Model {
    public function search($perPage = 6)
    {
        /*************搜索*********************/
        $keyword = I('get.keyword');
        $where = array();
        if($keyword)
        {
            $where['product_name'] = array('like','%'.$keyword.'%');
        }
        

        /*************翻页*******************/
        $count = $this->count();
        $pageObj = new \Think\Page($count,$perPage);
        $pageString = $pageObj->show();

        $data = $this->where($where)
                ->order('id')
                ->limit($pageObj->firstRow.','.$pageObj->listRows)
                ->select();
        
        //var_dump($data);die;
        return array(
            'goods'     =>  $data,
            'total'     =>  $count,
            );
    }
    public function cate()
    {
        $data = M('Good_cates')->select();
        $list = array();
        $i = 0;
        foreach ($data as $val) {
            $list[$i]['id'] = $val['id'];
            $list[$i]['pId'] = $val['parent_id'];
            $list[$i]['name'] = $val['cate_name'];
            $i+=1;
        }

        return json_encode($list);
    }
}